package com.zyf.rxjavaapp.utils

import android.os.Environment
import okhttp3.Cache
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.io.File


/**
 * 作者：Think
 * 创建于 2017/4/1 09:52
 */
object ServiceUtils{
    private val API_BASE_URL = "http://lf.snssdk.com/"
    private val httpClient = OkHttpClient.Builder()
   /* var httpCacheDirectory = File(Environment.getExternalStorageDirectory(), "Connotation")//这里为了方便直接把文件放在了SD卡根目录的HttpCache中，一般放在context.getCacheDir()中
    var cacheSize = 10 * 1024 * 1024L//设置缓存文件大小为10M
    var cache = Cache(httpCacheDirectory, cacheSize)  .cache(cache)*/
    private val builder = Retrofit.Builder()
            .baseUrl(API_BASE_URL)
            .addConverterFactory(ScalarsConverterFactory.create())
            //.addConverterFactory(GsonConverterFactory.create())
            .client(httpClient.build())
            .build()

    fun <S> createService(serviceClass: Class<S>): S {
        return builder.create(serviceClass)
    }
}